import request from '@/utils/request'

/**
 * 提交报修申请
 * @param {Object} data: { type_id: 报修类型id, problem: 问题描述, place: 报修地点, phone: 手机号, p_name: 图片url}
 * @return Promise
 */
export const repairRequestAPI = (data) => {
  return request({
    url: '/reception/repair/add',
    method: 'POST',
    data
  })
}

/**
 * 修改报修申请
 * @param {Object} data: { type_id: 报修类型id, problem: 问题描述, place: 报修地点, phone: 手机号, p_name: 图片url}
 * @return Promise
 */
export const updateRepairRequestAPI = (data) => {
  return request({
    url: '/reception/repair/update',
    method: 'PATCH',
    data
  })
}

/**
 * 获取报修单列表
 * @param {Object} data: { page, pagesize, type_id}
 * @return Promise
 */
export const getMyRepairListAPI = (data) => {
  return request({
    url: '/reception/repair/',
    method: 'POST',
    data
  })
}

/**
 * 获取报修单数量统计
 * @return Promise
 */
export const getContAPI = () => {
  return request({
    url: '/common/cont/'
  })
}

/**
 * 接单/退单报修单
 * @param {Object} data: { id, isReturn: 是否退回 }
 * @return Promise
 */
export const returnRepairAPI = (data) => {
  return request({
    url: '/reception/repair/return/',
    method: 'patch',
    data
  })
}

/**
 * 学生确认完成维修/未完成维修
 * @param {Object} data: { id, isReturn: 是否退回 }
 * @return Promise
 */
export const affirmRepairAPI = (data) => {
  return request({
    url: '/reception/repair/affirm/',
    method: 'patch',
    data
  })
}

/**
 * 获取报修单信息
 * @param id
 * @return Promise
 */
export const getRepairInfoAPI = (id) => {
  return request({
    url: `/common/repair/${id}`
  })
}

/**
 * 用户查询报修单
 * @param data
 * @return Promise
 */
export const queryRepairAPI = (data) => {
  return request({
    url: '/reception/repair/query',
    method: 'POST',
    data
  })
}

/**
 * 管理员查询报修单
 * @param data
 * @return Promise
 */
export const queryRepairMAPI = (data) => {
  return request({
    url: '/manage/repair/query',
    method: 'POST',
    data
  })
}

/**
 * 获取报修单列表
 * @param {Object} data: { page: 页码, pagesize: 每页条数, type_id: 报修类型, state: 状态, a_id: 受理人id, r_id: 维修人员id }
 * @return Promise
 */
export const getRepairListAPI = (data) => {
  return request({
    url: '/manage/repair/',
    method: 'POST',
    data
  })
}

/**
 * 修改报修单状态
 * @param {Object} data: { id, state: 状态}
 * @return Promise
 */
export const updateRepairAPI = (data) => {
  return request({
    url: '/manage/repair/',
    method: 'PATCH',
    data
  })
}

/**
 * 审核报修单
 * @param {Object} data: { id, is_adopt: 是否通过 }
 * @return Promise
 */
export const examineRepairAPI = (data) => {
  return request({
    url: '/manage/repair/pass',
    method: 'POST',
    data
  })
}
